/*
 * @Author: hongbin
 * @Date: 2023-10-12 13:38:07
 * @LastEditors: hongbin
 * @LastEditTime: 2023-10-12 14:58:24
 * @Description: 定义projects模型结构
 */
import { Schema, model } from "mongoose";

const ObjectId = Schema.ObjectId;

const ProjectSchema = new Schema({
  title: String,
  order: Number,
});

//设置自动插入的版本号名称 默认 __v
//每次有数组变动会自动 + 1 防止并发错误
//如果要针对所有字段都进行版本控制，需要使用mongoose的插件：mongoose - update -if-current
ProjectSchema.set("versionKey", "__v");

const ProjectsModel = model("projects", ProjectSchema);

console.log(await ProjectsModel.find({ title: "React" }));

// ProjectsModel.methods = {
//   log: function () {
//     console.log(this);
//   },
// };
